const express = require("express");
const app = express();

// 允许跨域访问
app.use((req, res, next) => {
  res.header("Access-Control-Allow-Origin", "*");
  res.header(
    "Access-Control-Allow-Headers",
    "Origin, X-Requested-With, Content-Type, Accept"
  );
  next();
});

// 定义接口路由
app.get("/limao/applet/getAllAgreementName", (req, res) => {
  const data = {
    code: 200,
    msg: "操作成功",
    data: [
      { agreementName: "用户隐私协议" },
      { agreementName: "用户押金协议" },
      { agreementName: "用户租换协议" },
      { agreementName: "登录协议" }
    ]
  };

  res.json(data);
});

app.get("/limao/applet/getUserAgreement", (req, res) => {
  // 根据agreementName查询数据库或其他数据源获取协议信息
  // 这里使用硬编码的方式返回示例数据
  const agreement = {
    code: 200,
    msg: "操作成功",
    data: {
      id: "1",
      agreementName: "用户隐私协议",
      agreementContent:
        '<p style="text-align: left;"><br></p><h1 style="text-align: center; line-height: 1.5;">本隐私权政策属于锂猫电吧服务使用协议不可分割的一部分。</p><p style="text-align: start; line-height: 1.5;"></p>'
    }
  };

  res.json(agreement);
});

// 启动服务器
const port = 3000;
app.listen(port, () => {
  console.log(`Server is running on port ${port}`);
});
